<template>
  <!-- 已发文查询 -->
  <div class="pro_document_response.data.records">

    <div style="padding:10px; background:#fff">
      <el-card>
        <el-input v-model="searchForm.name" placeholder="请输入公文标题" style="width: 150px" clearable></el-input>
        <el-select v-model="searchForm.type" placeholder="发文类别" style="width: 150px; margin-left: 8px" filterable clearable>
          <el-option v-for="item in addDialog.types" :key="item.type" :value="item.type" :label="item.type"/>
        </el-select>
        <el-select v-model="searchForm.security" placeholder="安全权限" style="width: 150px; margin-left: 8px" filterable clearable>
          <el-option v-for="item in addDialog.securities" :key="item.security" :value="item.security" :label="item.security"/>
        </el-select>
        <el-select v-model="searchForm.department" placeholder="发文部门" style="width: 150px; margin-left: 8px" filterable clearable>
          <el-option v-for="item in addDialog.departments" :key="item.department" :value="item.department" :label="item.department"/>
        </el-select>
        <el-date-picker
          style="margin: 8px"
          v-model="searchTime"
          unlink-panels
          value-format="timestamp"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
        <el-button style="margin-right: 6px" type="primary" icon="el-icon-search" size="small" @click="toSearch">查询</el-button>
      <!--  :loading="loading"-->
      <!--  :scroll="documents.length>0?{x:1300}:{}"-->
        <a-table
          :bordered="true"
          style="margin-top: 10px"
          :data-source="documents"
          size="small"
          :pagination="pagination"
          :rowKey="record => record.id"
          >
          <a-table-column :width="50" title="序号" align="center">
            <template slot-scope="text, record, index">
              {{index+1}}
            </template>
          </a-table-column>
          <a-table-column :width="400" key="name" title="公文标题" data-index="name" ellipsis="true" align="center"/>
          <a-table-column :width="150" key="type" title="类别" data-index="type" ellipsis="true" align="center"/>
          <a-table-column :width="100" key="security" title="安全权限" data-index="security" ellipsis="true" align="center"/>
          <a-table-column :width="100" key="fileNo" title="档案号" data-index="fileNo" ellipsis="true" align="center"/>
          <a-table-column :width="100" key="department" title="发文部门" data-index="department" ellipsis="true" align="center"/>
          <a-table-column :width="115" key="fileId" title="发文" data-index="fileId" ellipsis="true" align="center">
            <template slot-scope="text, record">
              <el-tag type="info" v-if="record.url === null || record.url === ''">无文件</el-tag>
              <el-button type="primary" v-else plain size="mini" @click="viewFile(record.url)">查看</el-button>
            </template>
          </a-table-column>
          <a-table-column key="updateTime" title="发文时间" data-index="updateTime" ellipsis="true" align="center">
            <template slot-scope="text, record">
              {{dateTimeFormat(record.updateTime)}}
            </template>
          </a-table-column>
        </a-table>
      </el-card>
    </div>
  </div>
</template>
<script>
  import '@/styles/auto-style.css'
  import { dateTimeFormat,nullFormat } from '@/utils/format'
  import {getAction, postActionByJson, postActionByQueryString} from "@/api/manage";

  export default {
    data() {
      return {
        url: {
          findAllType: '/document/type/selectAllType',
          findAllSecurity: '/document/security/selectAllSecurity',
          findAllLevel: '/document/level/selectAllLevel',
          findAllDepartment: '/document/department/selectAllDepartment',
          selectDocumentSendOut: '/document/selectDocumentSendOut',
        },
        searchTime: [], // 用来接收查询时间
        searchForm: {},
        documents: [],
        addDialog: {
          addForm: {},
          title: '',
          visible: false,
          items: []
        },
        loading: true,
        pagination: {
          showTotal: total => `共 ${total} 条结果`,
          showQuickJumper: true,
          showSizeChanger: true,
          pageSizeOptions: ['1', '2', '5', '10'],
          pageNum: 1,
          pageSize: 10,
          total: 0,
          onChange: (pageNum) =>  {
            this.pagination.pageNum = pageNum
            this.toSearch()
          },
          onShowSizeChange: (pageNum, pageSize) => {
            this.pagination.pageSize = pageSize
            this.toSearch()
          } // 改变每页数量时更新显示
        }
      }
    },
    created() {
      this.toSearch()
      this.selectTypes()
      this.selectSecurities()
      this.selectLevels()
      this.selectDepartments()
    },
    methods: {
      viewFile(url) {
        if (url) {
          // window.open("http://218.87.96.53:14008/xzx/images/20210914-120629-test.pdf");
          window.open(url);
        }else {
          this.$message.warning("未上传发文！")
        }
      },
      toSearch() {
        if (this.searchTime) {
          this.searchForm.startTime = this.searchTime[0]
          this.searchForm.endTime = this.searchTime[1]
        }else {
          this.searchForm.startTime = ''
          this.searchForm.endTime = ''
        }
        this.searchForm.pageNum = this.pagination.pageNum
        this.searchForm.pageSize = this.pagination.pageSize
        getAction(this.url.selectDocumentSendOut, this.searchForm)
          .then(resp => {
            console.log(resp.data.records)
            this.documents = resp.data.records
            this.pagination.pageSize = parseInt(resp.data.size)
            this.pagination.total = parseInt(resp.data.total)
            this.loading = false
          }).catch((item)=>{
            console.log(item)
            this.loading = false
          // this.$message( {type : 'warning', message : '添加失败'} )
          // this.$message.warning(item)
        })
      },
      selectTypes() {
        this.addDialog.types = []
        getAction(this.url.findAllType)
          .then(resp => {
            this.addDialog.types = resp.data
          })
      },
      selectSecurities() {
        this.addDialog.securities = []
        getAction(this.url.findAllSecurity)
          .then(resp => {
            this.addDialog.securities = resp.data
          })
      },
      selectLevels() {
        this.addDialog.levels = []
        getAction(this.url.findAllLevel)
          .then(resp => {
            this.addDialog.levels = resp.data
          })
      },
      selectDepartments() {
        this.addDialog.departments = []
        getAction(this.url.findAllDepartment)
          .then(resp => {
            this.addDialog.departments = resp.data
          })
      },
      selectItems(item) {
        this.addDialog.types = []
        this.addDialog.securities = []
        this.addDialog.levels = []
        this.addDialog.departments = []
        let requestUrl
        if (item != null) {
          switch (item) {
            case 'type': requestUrl = this.url.findAllType; break;
            case 'security': requestUrl = this.url.findAllSecurity; break;
            case 'level': requestUrl = this.url.findAllLevel; break;
            case 'department': requestUrl = this.url.findAllDepartment; break;
          }
          console.log(item)
          getAction(requestUrl)
            .then(resp => {
              this.addDialog.items = resp.data
            })
          // .catch((e)=> {console.log(e)})
          // .finally(()=>{
          //   this.$message.warning("请求异常")
          // })
        } else {
          this.$message.warning("请求参数为null")
        }
      },
      dateTimeFormat,
      loadPools() {
      },
    }
  }
</script>
<style lang="scss" scoped>
  .el-card {
    height: 618px;
  }
  /deep/.el-card__body {
    padding-top: 10px;
    padding-left: 23px;
    padding-right: 23px;
  }
</style>
